package com.jams.goodox.activity.mine.settings;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.SePref;
import com.jams.goodox.activity.login.RegistActivity;
import com.jams.goodox.activity.login.RoleChooseActivity;
import com.jams.goodox.entity.UploadImgResult;
import com.jams.goodox.net.BaseEntity;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.LoginService;
import com.jams.goodox.net.services.MineService;
import com.jams.goodox.utils.StatusBarCompat;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.utils.ToastUtil;
import com.jams.goodox.utils.UImageUtils;

import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import uama.hangzhou.image.photochoose.PhotoChoose;
import uama.hangzhou.image.widget.MyGridView;

/**
 * Description 使用建议反馈
 * @author HP
 */
public class MineFeedback extends BaseActivity {

	private static final String TAG = "MineFeedback";
	@Bind(R.id.input_box)
	EditText inputBox;

	@Override
	protected int getLayoutId() {
		return R.layout.mine_feedback;
	}

	@Override
	protected void init() {

		StyleUtil.titleBackKey(this, "意见反馈");
		StatusBarCompat.compat(this, ContextCompat.getColor(this, R.color.main_theme));//沉侵式头部
	}

	private void submit() {
		if(TextUtils.isEmpty(inputBox.getText())){
			ToastUtil.show("请输入反馈内容");
			return;
		}

		clearMap();
		StringBuilder pData = new StringBuilder();
		pData.append("content:" + inputBox.getText().toString())
				.append(",mobile:" + SePref.getPrePhone())
				.append(",memberId:" + SePref.getId());

		params.put("requestData", "{" + pData.toString() + "}");

		String strEntity = gson.toJson(params);
		RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),strEntity);

		showLoading();

		Call<ResponseBody> example = createCallService(LoginService.class).feedBack(body);

		example.enqueue(new Callback<ResponseBody>() {
			@Override
			public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
				misLoading();
				try {
					String data = response.body().string();
					Log.d(TAG, "data = " + data);

					JSONObject jsonObject = new JSONObject(data);

					if(200 == jsonObject.getInt("code")){
						ToastUtil.show("提交成功");

						finish();

					}else {
						if(jsonObject.has("error")){
							ToastUtil.show("error:" + jsonObject.getString("error") );
						}else {
							ToastUtil.show("网络异常！" );
						}
					}
				} catch (Exception e) {
					ToastUtil.show("Exception:" + e.getMessage());
				}

			}

			@Override
			public void onFailure(Call<ResponseBody> call, Throwable t) {
				misLoading();
				Log.d(TAG,"onFailure = " + t.getMessage());
			}
		});


	}

	@OnClick({ R.id.submit })
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.submit:
				submit();
				break;
		}
	}
}
